package com.qj.yantaishan.controller;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.ExpressTpl;
import com.qj.yantaishan.service.IExpressTplService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 快递单打印模板Controller
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/ExpressTpl")
public class ExpressTplController extends BaseController
{
    private String prefix = "yantaishan/ExpressTpl";

    @Autowired
    private IExpressTplService expressTplService;

    @RequiresPermissions("yantaishan:tpl:view")
    @GetMapping()
    public String tpl()
    {
        return prefix + "/tpl";
    }

    /**
     * 查询快递单打印模板列表
     */
    @RequiresPermissions("yantaishan:tpl:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExpressTpl expressTpl)
    {
        startPage();
        List<ExpressTpl> list = expressTplService.selectExpressTplList(expressTpl);
        return getDataTable(list);
    }

    /**
     * 导出快递单打印模板列表
     */
    @RequiresPermissions("yantaishan:tpl:export")
    @Log(title = "快递单打印模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExpressTpl expressTpl)
    {
        List<ExpressTpl> list = expressTplService.selectExpressTplList(expressTpl);
        ExcelUtil<ExpressTpl> util = new ExcelUtil<ExpressTpl>(ExpressTpl.class);
        return util.exportExcel(list, "快递单打印模板数据");
    }

    /**
     * 新增快递单打印模板
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存快递单打印模板
     */
    @RequiresPermissions("yantaishan:tpl:add")
    @Log(title = "快递单打印模板", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExpressTpl expressTpl)
    {
        return toAjax(expressTplService.insertExpressTpl(expressTpl));
    }

    /**
     * 修改快递单打印模板
     */
    @RequiresPermissions("yantaishan:tpl:edit")
    @GetMapping("/edit/{tplId}")
    public String edit(@PathVariable("tplId") Long tplId, ModelMap mmap)
    {
        ExpressTpl expressTpl = expressTplService.selectExpressTplByTplId(tplId);
        mmap.put("expressTpl", expressTpl);
        return prefix + "/edit";
    }

    /**
     * 修改保存快递单打印模板
     */
    @RequiresPermissions("yantaishan:tpl:edit")
    @Log(title = "快递单打印模板", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExpressTpl expressTpl)
    {
        return toAjax(expressTplService.updateExpressTpl(expressTpl));
    }

    /**
     * 删除快递单打印模板
     */
    @RequiresPermissions("yantaishan:tpl:remove")
    @Log(title = "快递单打印模板", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(expressTplService.deleteExpressTplByTplIds(ids));
    }
}
